package com.employees.action;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.employees.bean.Employee;
import com.employees.bean.EmployeeBase;
import com.employees.bean.Employeeinfo;
import com.employees.bean.Pager;
import com.employees.bean.Result;
import com.employees.service.EmployeeService;

public class EmployeeSearch extends Action {
	
	private int page;
	private EmployeeService EService;

	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public EmployeeService getEService() {
		return EService;
	}

	public void setEService(EmployeeService eService) {
		EService = eService;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
			String name=request.getParameter("employeeName");
			String depart=request.getParameter("employeeDepart");
			String sex=request.getParameter("sex");
			String  hql = EService.getHql(name, depart, sex);
			
			System.out.println(hql);
			
			Pager pager=new Pager();
			pager.setEveryPage(10);//设置每页显示的条数
			String p=request.getParameter("currentPage");
			if (p != null) {
				page = Integer.parseInt(p);
			} else {
				page = 1;
			}
			pager.setCurrentPage(page);//为第一页
			Result result=EService.findByPage(pager,hql);
			request.setAttribute("list",result.getList());
			request.setAttribute("pager", result.getPager());
			

			return mapping.findForward("success");
	}
	

}
